// pages/brochure/byxItem/houserTypeScroll.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件参数设置，传递到组件
    defaultData: {
      title: "", // 导航栏标题
      showHome: false, //是否显示回到首页按钮
      showBack: true, //是否显示返回按钮
      showLogo: false, //是否显示logo
      showViewBox: true,
      bgColor: '#242D35',
      isShare: 0
    },
    baseUrl: app.baseUrl,
    version: app.globalData.version,
    requestUrl: app.baseUrl,
    shareTitle: '',
    shareImg: '',
    imgName: "",
    viewWidth: wx.getSystemInfoSync().windowWidth,
    viewHeight: wx.getSystemInfoSync().windowHeight,
    imgTop: 0,
    openid: ''
  },
  //获取微信分享信息
  getShareInfo(openid) {
    var that = this;
    wx.request({
      url: that.data.requestUrl + 'getLsShareInfo.php',
      method: 'POST',
      data: {
        type: 2,
        openid: openid
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        that.setData({
          shareTitle: res.data.shareTitle,
          shareImg: res.data.shareImg
        });
      },
      fail: function (res) {}
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    var is_share = options.is_share;
    //判断返回的跳转路径
    if (is_share == 1) {
      this.setData({
        ['defaultData.isShare']: 1
      });
    }

    var typeId = options.typeId;
    console.log(typeId)
    if (typeId == '' || typeId == undefined) {

    } else {
      this.setData({
        imgName: typeId
      });
    }

    //获取缓存中的openid
    var openid = wx.getStorageSync('openid');

    if (openid == '') {
      //缓存中没有openid
      //获取所需页面信息
      wx.login({
        success: function (res) {
          if (res.code) {
            //发起网络请求
            wx.request({
              url: that.data.requestUrl + 'getOpenid.php',
              method: 'POST',
              data: {
                'code': res.code
              },
              header: {
                'content-type': 'application/x-www-form-urlencoded'
              },
              success: function (res) {
                //缓存微信openid
                wx.setStorageSync('openid', res.data.openid);
                that.setData({
                  openid: res.data.openid
                });

                //调用分享
                that.getShareInfo(res.data.openid);
              },
              fail: function (res) {}
            });
          }
        }
      });
    } else {
      that.setData({
        openid: openid
      });

      //调用分享
      that.getShareInfo(openid);
    }
  },



  imgH(e) {
    var winWid = wx.getSystemInfoSync().windowWidth;
    var winHid = wx.getSystemInfoSync().windowHeight;
    var imgh = e.detail.height;
    var imgw = e.detail.width;
    var swiperH = (winHid - (winWid * imgh / imgw)) / 2 - 44;
    this.setData({
      imgTop: swiperH / 2
    })
    console.log(swiperH)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var that = this;
    return {
      title: that.data.shareTitle,
      path: '/pages/brochure/index?is_share=1',
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  },
  // 分享朋友圈
  onShareTimeline() {
    var that = this;
    return {
      title: that.data.shareTitle,
      query: 'is_share=1',
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  }
})